<template>
<div>
  <home-header>home-header</home-header>
  <home-swiper :list="swiperList">home-swiper</home-swiper>
  <home-icons :list="iconList">home-swiper</home-icons>
  <home-recommend :list="recommendList">home-recommend</home-recommend>
  <home-weekend :list="weekendList">home-recommend</home-weekend>
</div>
</template>
<script>
import HomeHeader from './components/Header'
import HomeSwiper from './components/Swiper'
import HomeIcons from './components/Icons'
import HomeRecommend from './components/Recommend'
import HomeWeekend from './components/Weekend'
import axios from 'axios'
import { mapState } from 'vuex'
export default {
  name: 'Home',
  components: {
    HomeHeader,
    HomeSwiper,
    HomeIcons,
    HomeRecommend,
    HomeWeekend
  },
  data () {
	  return{	   
      lastCity:'',
	    swiperList:[],
      iconList:[],
      recommendList:[],
      weekendList:[],
      imgs:[]
	  }
  },
  computed: {
     ...mapState({currentCity:'city'})
  },
  methods:{
    getHomeInfo () {
       axios.get('/api/index.json?city='+this.currentCity).then(this.getHomeInfoSucc)
    },
    getHomeInfoSucc (res){
       res = res.data
       if(res.ret && res.data){        
         const data = res.data
         //console.log(data)        
         //console.log(data.swiperList)
         //console.log(data.iconList)
         this.swiperList = data.swiperList
         this.iconList = data.iconList
         this.recommendList = data.recommendList      
         this.weekendList = data.weekendList

         this.weekendList.forEach((item,index) =>{         
             this.imgs.push(item.imgUrl)
         })           
         localStorage.imgs = JSON.stringify(this.imgs)

       }
    },
    logs (){
     //console.log('abc')
    }
  },
  mounted () {
    console.log('I am mounted')
    this.lastCity = this.currentCity
    this.getHomeInfo(),
    this.logs()
  },
  activated (){//外层是keep-alive
    console.log('I am actived')
    if(this.lastCity != this.currentCity){
        console.log('zoule')
        this.lastCity = this.currentCity
        this.getHomeInfo()
    }   
  }
}
</script>
<style>
</style>
